﻿// Main url for pointing to WebAPI OData
////var endPoint = "http://doctalkdevice.com/DocTalkDevice/DocTalkWebAPI/odata";
var endPoint = "https://localhost/ICD10WebApiOData/odata";

/*For example, if you have the URL:
http://www.example.com/?me=myValue&name2=SomeOtherValue
    This code will return:
{
        "me"    : "myValue",
        "name2" : "SomeOtherValue"
    }
    and you can do:
    
            var me = getUrlVars()["me"];
var name2 = getUrlVars()["name2"];*/
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function s4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

function newGuid() {
    // then to call it, plus stitch in '4' in the third group
    return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
}

function decode(obj) {
    return decodeURIComponent(obj.replace(/\+/g, " "));
}

function getToday() {
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var today = now.getFullYear() + "-" + (month) + "-" + (day);
    return today;
}

String.prototype.endsWith = function (suffix) {
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

Storage.prototype.setObject = function (key, value) {
    this.setItem(key, JSON.stringify(value));
}

Storage.prototype.getObject = function (key) {
    return JSON.parse(this.getItem(key));
}

